/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentacion;


import ModeloLogicoSistema.AdministradorOrden;
import ModeloLogicoSistema.Orden;
import ModeloLogicoSistema.AdministradorCliente;
import ModeloLogicoSistema.Cliente;
import ModeloLogicoSistema.Imprimir_ticket;
import ModeloLogicoSistema.ServicioContratado;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;



/**
 *
 * @author debo
 */
public class BuscarOrden extends javax.swing.JDialog {
   
     String nombre;
             String calle ;
             Integer numcalle;
             String  telefono;
             String  fechapedido;
             String fechaentrega;
             Integer cantidad;
             String  descripcion;
             String detalle   ;
             Double preciototal ; 
             Double descuento;
             Double sena ;
             Double saldo ;

    private ArrayList<Orden> ordenes=null;
    private AdministradorOrden admOrdenes;
    private AdministradorCliente admCliente;
    private Orden orden=null;
    private SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
    
  ModificacionOrden modOrden;
  
   private void cargarTodasLasOrdenes() throws SQLException{
       this.ordenes=null;
       this.ordenes=(ArrayList)admOrdenes.cargarTodasLasOrdenes();
   }   
    public BuscarOrden(java.awt.Frame parent, boolean modal) throws SQLException {
        super(parent, modal);
        initComponents();
        
        jDateChooser1.setVisible(true);
        this.setLocationRelativeTo(null);
        this.setTitle("      Buscar Orden ");
        
        this.ordenes=new ArrayList<>();
        this.admOrdenes = new AdministradorOrden();
        this.admCliente = new AdministradorCliente();
        ordenes=(ArrayList<Orden>)this.admOrdenes.mostrarTodasLasOrdenes();
        Collections.sort(ordenes, new Orden(0));
        cargarTablaOrdenes();
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tablaOrden = new javax.swing.JTable();
        BtnCancelar = new javax.swing.JButton();
        jCBBusqueda = new javax.swing.JComboBox();
        txtBusqueda = new javax.swing.JTextField();
        BtnBuscar = new javax.swing.JButton();
        BtnModificar = new javax.swing.JButton();
        BtnEliminar = new javax.swing.JButton();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jDateChooser1.setVisible(false);
        btnLimpiarSeleccion = new javax.swing.JButton();
        btnImprimir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        tablaOrden.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Orden", "NroC.", "Cliente", "Fecha Pautada/Entrega", "Hora Pautada/Entrega", "Monto", "Seña", "Deuda", "Delivery", "Estado"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tablaOrden);
        tablaOrden.getColumnModel().getColumn(0).setPreferredWidth(75);
        tablaOrden.getColumnModel().getColumn(1).setPreferredWidth(75);
        tablaOrden.getColumnModel().getColumn(2).setPreferredWidth(150);
        tablaOrden.getColumnModel().getColumn(3).setPreferredWidth(125);
        tablaOrden.getColumnModel().getColumn(4).setPreferredWidth(125);
        tablaOrden.getColumnModel().getColumn(5).setPreferredWidth(75);
        tablaOrden.getColumnModel().getColumn(6).setPreferredWidth(75);
        tablaOrden.getColumnModel().getColumn(7).setPreferredWidth(75);

        BtnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        BtnCancelar.setText("Cancelar");
        BtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCancelarActionPerformed(evt);
            }
        });

        jCBBusqueda.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "idOrden", "idCliente", "Lista", "Pendiente" }));
        jCBBusqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBBusquedaActionPerformed(evt);
            }
        });

        txtBusqueda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBusquedaActionPerformed(evt);
            }
        });

        BtnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Buscar.png"))); // NOI18N
        BtnBuscar.setText("Buscar");
        BtnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnBuscarActionPerformed(evt);
            }
        });

        BtnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Modificar.png"))); // NOI18N
        BtnModificar.setText("Modificar");
        BtnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnModificarActionPerformed(evt);
            }
        });

        BtnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/quitar.png"))); // NOI18N
        BtnEliminar.setText("Anular");
        BtnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnEliminarActionPerformed(evt);
            }
        });

        jDateChooser1.setDateFormatString("dd/MM/yyyy");

        btnLimpiarSeleccion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/refresh.png"))); // NOI18N
        btnLimpiarSeleccion.setText("Refrescar");
        btnLimpiarSeleccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarSeleccionActionPerformed(evt);
            }
        });

        btnImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/print.png"))); // NOI18N
        btnImprimir.setText("Imprimir");
        btnImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BtnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(BtnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(BtnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jCBBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnLimpiarSeleccion, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCBBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(BtnBuscar))
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLimpiarSeleccion))
                .addGap(19, 19, 19)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnCancelar)
                    .addComponent(BtnModificar)
                    .addComponent(BtnEliminar)
                    .addComponent(btnImprimir))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_BtnCancelarActionPerformed

    private void BtnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnModificarActionPerformed
        try {
            Integer codOrden=null;
            try{
               
                Integer fila=this.tablaOrden.getSelectedRow();
                if(fila==-1){
                    throw new Exception("No ha seleccionado una orden."); 
                }
                codOrden=(Integer)this.tablaOrden.getValueAt(fila, 0);
                Integer ultPosicion=this.tablaOrden.getColumnCount()-1;
                String estado= this.tablaOrden.getValueAt(fila,ultPosicion).toString();
                if(estado.equalsIgnoreCase("ANULADA")){
                    throw new Exception("La orden seleccionada, esta anulada, no puede modificarla."); 
                }
                modOrden=new ModificacionOrden(null, rootPaneCheckingEnabled);
            }catch(Exception e){
                String mensaje=e.getMessage();
                JOptionPane.showMessageDialog(null,mensaje);
            }
            
           
            try{
                modOrden.iniciarComponentes(codOrden);
            }catch(Exception e){}
            //modOrden.setVisible(true);
            this.cargarTodasLasOrdenes();
            Collections.sort(ordenes, new Orden(0));
            this.cargarTablaOrdenes();
            
            //this.cargarTablaOrdenes();
        } catch (SQLException ex) {
            //Logger.getLogger(BuscarOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_BtnModificarActionPerformed

    private void txtBusquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBusquedaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtBusquedaActionPerformed

    
    private void BtnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnBuscarActionPerformed
        String eleccionBusqueda =jCBBusqueda.getSelectedItem().toString();
        String eleccionfecha = jDateChooser1.getDateFormatString();
        
        this.ordenes=new ArrayList<> ();
        if(eleccionBusqueda.equalsIgnoreCase("IdOrden")){
            if(txtBusqueda.getText().isEmpty()){
                try {
                    this.cargarTodasLasOrdenes();
                    Collections.sort(ordenes, new Orden(0));
                } catch (SQLException ex) {
                    Logger.getLogger(BuscarOrden.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else{
                try{
                    Integer valorBusqueda=new Integer (txtBusqueda.getText());
                    ordenes.add(this.admOrdenes.cargarOrden(valorBusqueda));
                }catch(Exception e){
                    JOptionPane.showMessageDialog(null, "No puede ingresar letras en el código de orden ");
                    return;
                }
            }
            this.cargarTablaOrdenes();
        }
        if(eleccionBusqueda.equalsIgnoreCase("idCliente")){
            if( txtBusqueda.getText().isEmpty()){
                try {
                    Comparator<Orden> comparadorCliente = new Comparator<Orden>() {

                        @Override
                        public int compare(Orden o1, Orden o2) {
                        return o1.getCodCliente()-o2.getCodCliente();
                        }
                    };
                    this.cargarTodasLasOrdenes();
                    Collections.sort(ordenes, comparadorCliente);
                } catch (SQLException ex) {
                    Logger.getLogger(BuscarOrden.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else{
                try{
                    Integer valorBusqueda=new Integer(txtBusqueda.getText());
                    ordenes=(ArrayList<Orden>) this.admOrdenes.buscarOrdenesPorCliente(valorBusqueda);}
                catch(Exception e){
                    JOptionPane.showMessageDialog(null, "No puede ingresar letras en el codigo de cliente");
                    return;
                }
            }
            
            this.cargarTablaOrdenes();
        }
        if(eleccionBusqueda.equalsIgnoreCase("Lista")){
            ordenes=(ArrayList<Orden>) this.admOrdenes.buscarOrdenesRealizadas();
            Collections.sort(ordenes);
            try{
                /*
                Date fecha=this.jDateChooser1.getDate();
                String fechaPactada=formateador.format(fecha);
                obtenerOrdenesDeFecha(fechaPactada);*/
                Date fecha=this.jDateChooser1.getDate();
                String fechaPactada=formateador.format(fecha);
                this.ordenes=this.admOrdenes.buscarOrdenesListasPautadasPara(fechaPactada);
                Collections.sort(ordenes);
            }catch(Exception e){
            }
            this.cargarTablaOrdenes();
        }
        if(eleccionBusqueda.equalsIgnoreCase("Pendiente")){
            ordenes=(ArrayList<Orden>) this.admOrdenes.buscarOrdenesPendientes();
            Collections.sort(ordenes);
            try{
                /*
                Date fecha=this.jDateChooser1.getDate();
                String fechaPactada=formateador.format(fecha);
                obtenerOrdenesDeFecha(fechaPactada);*/
                Date fecha=this.jDateChooser1.getDate();
                String fechaPactada=formateador.format(fecha);
                this.ordenes=this.admOrdenes.buscarOrdenesPendientesPautadasPara(fechaPactada);
                Collections.sort(ordenes);
            }catch(Exception e){
            
            } 
            this.cargarTablaOrdenes();
        }   
    }//GEN-LAST:event_BtnBuscarActionPerformed

    private void jCBBusquedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBBusquedaActionPerformed
        String eleccion=this.jCBBusqueda.getSelectedItem().toString();
        if(eleccion.equalsIgnoreCase("Lista") & !this.jDateChooser1.isVisible()){
            jDateChooser1.setVisible(true);
            this.txtBusqueda.setVisible(false);
        }
        if(eleccion.equalsIgnoreCase("Pendiente") & !this.jDateChooser1.isVisible()){
            this.jDateChooser1.setVisible(true);
            this.txtBusqueda.setVisible(false);
        }
        if(eleccion.equalsIgnoreCase("IdOrden") & this.jDateChooser1.isVisible()){
            this.jDateChooser1.setVisible(false);
            this.txtBusqueda.setVisible(true);
        }
        if(eleccion.equalsIgnoreCase("IdCliente")& this.jDateChooser1.isVisible()){
            this.jDateChooser1.setVisible(false);
            this.txtBusqueda.setVisible(true);
        }
    }//GEN-LAST:event_jCBBusquedaActionPerformed

    private void BtnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnEliminarActionPerformed
        try{
        Integer row=this.tablaOrden.getSelectedRow();        // TODO add your handling code here:
        if(row==-1){
            throw new Exception("No ha seleccionado una orden para anular");
        }
        int cod=(Integer) this.tablaOrden.getValueAt(row, 0);
        int ultColumna=this.tablaOrden.getColumnCount()-1;
        String estado=this.tablaOrden.getValueAt(row, ultColumna).toString();
        if(estado.equalsIgnoreCase("ANULADA")){
            throw new Exception("La orden seleccionada ya ha sido eliminada.");
        }else if(estado.equalsIgnoreCase("LISTA")){
            throw new Exception("La orden seleccionada ya esta lista y almacenada.\n "
                    + "No puede eliminarse.");
        }else if(estado.equalsIgnoreCase("ENTREGADA")){
            throw new Exception("La orden seleccionada ya ha sido entregada.\n "
                    + "No puede eliminarse.");
        }
        int opcion=JOptionPane.showConfirmDialog(null, "¿Esta seguro de desear anular la orden?", "Anular Orden",
                JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
        if(opcion==JOptionPane.YES_OPTION){
            this.admOrdenes.anularOrden(cod);
            try {
                this.cargarTodasLasOrdenes();
                this.cargarTablaOrdenes();
            } catch (SQLException ex) {
                Logger.getLogger(BuscarOrden.class.getName()).log(Level.SEVERE, null, ex);
            }
        }}catch (Exception e){
            String mensaje= e.getMessage();
            JOptionPane.showMessageDialog(null, mensaje);
        }
        
    }//GEN-LAST:event_BtnEliminarActionPerformed

    private void btnLimpiarSeleccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarSeleccionActionPerformed
        try {
            this.cargarTodasLasOrdenes();
            /*if(txtBusqueda.isVisible()){
                Collections.sort(ordenes, new Orden(0));
            }
            else{
                Collections.sort(ordenes);
            }*/
            Collections.sort(ordenes, new Orden(0));
            this.cargarTablaOrdenes();
        } catch (SQLException ex) {
            Logger.getLogger(BuscarOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnLimpiarSeleccionActionPerformed

    private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
        Integer codOrden=null;
        Cliente cliente = null;    
        ArrayList<ServicioContratado> serviciosContratados;
        ArrayList<ServicioContratado> serviciosEspContratados;     
        try{
            Integer fila=this.tablaOrden.getSelectedRow();
            codOrden=(Integer)this.tablaOrden.getValueAt(fila, 0);
            orden=this.admOrdenes.cargarOrden(codOrden);
            cliente=this.admCliente.cargarCliente(orden.getCodCliente());
            //Listas con datos de los servicios contratados contienen precio, nombre, cantidad, y cod orden creo :P
            serviciosContratados=(ArrayList<ServicioContratado>) this.admOrdenes.mostrarTodosLosServiciosContratados(orden.getCodOrden());
            serviciosEspContratados=(ArrayList<ServicioContratado>)this.admOrdenes.mostrarTodosLosServiciosEspContratados(orden.getCodOrden());
            Imprimir_ticket impresion = new Imprimir_ticket();           
            impresion.imprimir(orden,cliente,serviciosContratados,serviciosEspContratados);
        }catch(Exception e){
            //JOptionPane.showMessageDialog(null,"No ha seleccionado ninguna orden");
        }
    }//GEN-LAST:event_btnImprimirActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
  /*      try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch ( ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BuscarOrden.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
    /*    java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                BuscarOrden dialog=null;
                try {
                    dialog = new BuscarOrden(new javax.swing.JFrame(), true);
                } catch (SQLException ex) {
                    Logger.getLogger(BuscarOrden.class.getName()).log(Level.SEVERE, null, ex);
                }
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }*/
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnBuscar;
    private javax.swing.JButton BtnCancelar;
    private javax.swing.JButton BtnEliminar;
    private javax.swing.JButton BtnModificar;
    private javax.swing.JButton btnImprimir;
    private javax.swing.JButton btnLimpiarSeleccion;
    private javax.swing.JComboBox jCBBusqueda;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tablaOrden;
    private javax.swing.JTextField txtBusqueda;
    // End of variables declaration//GEN-END:variables

    /*private Orden getOrdenSeleccionada() {
       int posicion=this.tablaOrden.getSelectedRow();
       if(posicion!=-1) {           
           this.orden= this.ordenes.remove(posicion);
           return this.orden;
       }
       return null;
    }*/
    
    

    private void cargarTablaOrdenes() {
        DefaultTableModel modeloTabla=(DefaultTableModel) this.tablaOrden.getModel();
        int cantFilas=modeloTabla.getRowCount();
        for(int i=0;i<cantFilas;i++){
            modeloTabla.removeRow(0);
        }
        
        for(Orden orden:ordenes){
            int cod=orden.getCodCliente();
            Cliente cliente=this.admCliente.cargarCliente(cod);
            Object[] fila={orden.getCodOrden(),cod,cliente.getNombre()+" "+cliente.getApellido(),
                orden.getFechaEntregaPactada(),orden.getHoraPactadaDesde(),orden.getMontoTotal(),orden.getMontoAbonado(),orden.getMontoAdeudado(),
            orden.tieneDelivery(),orden.getSituacionOrden()};
            
            modeloTabla.addRow(fila);
        }
    }


}
